﻿using System;
using System.Collections.Generic;



namespace BreadCrumbs
{
	/// <summary>
	/// Holds data about a breadcrumb path.
	/// </summary>
	public class BreadcrumbPath
	{
		private Breadcrumb _owner;
		private IDictionary<string, string> _levels;


		/// <summary>
		/// Initializes a new instance of the <see cref="BreadcrumbPath"/> class.
		/// </summary>
		/// <param name="owner">The breadcrumb that owns the breadcrumb path.</param>
		/// <exception cref="ArgumentNullException">owner is null</exception>
		public BreadcrumbPath(Breadcrumb owner)
		{
			if (owner == null)
				throw new ArgumentNullException("owner");

			_owner = owner;
			_levels = new Dictionary<string, string>();
		}


		/// <summary>
		/// Gets or sets the breadcrumb levels.
		/// </summary>
		/// <value>The breadcrumb levels.</value>
		internal IDictionary<string, string> Levels
		{
			get
			{
				return _levels;
			}
		}


		/// <summary>
		/// Adds a level to to breadcrumb path.
		/// </summary>
		/// <param name="title">The level title.</param>
		/// <param name="path">The level path.</param>
		/// <returns>The <see cref="BreadcrumbPath"/> instance, enabeling a fluent interface.</returns>
		/// <exception cref="ArgumentNullException">title is null</exception>
		/// <exception cref="ArgumentException">title is empty</exception>
		public BreadcrumbPath Add(string title, string path)
		{
			if (title == null)
				throw new ArgumentNullException("title");

			if (title.Length==0)
				throw new ArgumentException("Value cannot be empty.", "title");

			if (_owner == null)
				throw new InvalidOperationException("Owner cannot be null.");

			_levels.Add(title, path);
			return this;
		}


		/// <summary>
		/// Adds a level to to breadcrumb path.
		/// </summary>
		/// <param name="title">The level title.</param>
		/// <returns>The <see cref="BreadcrumbPath"/> instance, enabeling a fluent interface.</returns>
		/// <exception cref="ArgumentNullException">title is null</exception>
		/// <exception cref="ArgumentException">title is empty</exception>
		public BreadcrumbPath Add(string title)
		{
			if (title == null)
				throw new ArgumentNullException("title");

			if (title.Length==0)
				throw new ArgumentException("Value cannot be empty.", "title");

			return Add(title, null);
		}
	}
}
